package cn.fay.chapter10;

public class Test23 {

	public static void main(String[] args) {
		B b=new B(20);
		for (int i = 0; i < 20; i++) {
			b.addItems(new A().getU());
		}
		b.empty(5);
		b.traverse();
		

	}

}
interface U{
	void method1();
	void method2();
	void method3();
}
class A{
	
	public U getU(){
		return new U() {
			
			@Override
			public void method1(){
				System.out.println("method1");
			}
			@Override
			public void  method2() {
				System.out.println("method2");
			}
			@Override
			public void method3() {
				System.out.println("method3");
			}
		};
	}
}
class B{
	private U[] items;
	private int next=0;
	public B(int size){
		items=new U[size];
	}
	public void addItems(U u){
		if (next<items.length) {
			items[next++]=u;
		}
	}
	public void empty(int i){
		if (!(i>=0&&i<=items.length-1)) {
			return;
		}
		items[i]=null;
	}
	public void traverse(){
		for(int i=0; i<items.length; i++) {
			if (items[i]!=null) {
				items[i].method1();
				items[i].method2();
				items[i].method3();
			}
		}
	}
}